home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mario.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  173 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int gfx_bank,palette_bank;
  15.  
  16. unsigned char *mario_scrolly;
  17.  
  18. /***************************************************************************
  19.  
  20.   Convert the color PROMs into a more useable format.
  21.  
  22.   Mario Bros. has a 512x8 palette PROM; interstingly, bytes 0-255 contain an
  23.   inverted palette, as other Nintendo games like Donkey Kong, while bytes
  24.   256-511 contain a non inverted palette. This was probably done to allow
  25.   connection to both the special Nintendo and a standard monitor.
  26.   The palette PROM is connected to the RGB output this way:
  27.  
  28.   bit 7 -- 220 ohm resistor -- inverter  -- RED
  29.         -- 470 ohm resistor -- inverter  -- RED
  30.         -- 1  kohm resistor -- inverter  -- RED
  31.         -- 220 ohm resistor -- inverter  -- GREEN
  32.         -- 470 ohm resistor -- inverter  -- GREEN
  33.         -- 1  kohm resistor -- inverter  -- GREEN
  34.         -- 220 ohm resistor -- inverter  -- BLUE
  35.   bit 0 -- 470 ohm resistor -- inverter  -- BLUE
  36.  
  37. ***************************************************************************/
  38. void mario_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2;
  48.  
  49.  
  50.         /* red component */
  51.         bit0 = (*color_prom >> 5) & 1;
  52.         bit1 = (*color_prom >> 6) & 1;
  53.         bit2 = (*color_prom >> 7) & 1;
  54.         *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  55.         /* green component */
  56.         bit0 = (*color_prom >> 2) & 1;
  57.         bit1 = (*color_prom >> 3) & 1;
  58.         bit2 = (*color_prom >> 4) & 1;
  59.         *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  60.         /* blue component */
  61.         bit0 = (*color_prom >> 0) & 1;
  62.         bit1 = (*color_prom >> 1) & 1;
  63.         *(palette++) = 255 - (0x55 * bit0 + 0xaa * bit1);
  64.  
  65.         color_prom++;
  66.     }
  67.  
  68.     /* characters use the same palette as sprites, however characters */
  69.     /* use only colors 64-127 and 192-255. */
  70.     for (i = 0;i < 8;i++)
  71.     {
  72.         COLOR(0,4*i) = 8*i + 64;
  73.         COLOR(0,4*i+1) = 8*i+1 + 64;
  74.         COLOR(0,4*i+2) = 8*i+2 + 64;
  75.         COLOR(0,4*i+3) = 8*i+3 + 64;
  76.     }
  77.     for (i = 0;i < 8;i++)
  78.     {
  79.         COLOR(0,4*i+8*4) = 8*i + 192;
  80.         COLOR(0,4*i+8*4+1) = 8*i+1 + 192;
  81.         COLOR(0,4*i+8*4+2) = 8*i+2 + 192;
  82.         COLOR(0,4*i+8*4+3) = 8*i+3 + 192;
  83.     }
  84.  
  85.     /* sprites */
  86.     for (i = 0;i < TOTAL_COLORS(1);i++)
  87.         COLOR(1,i) = i;
  88. }
  89.  
  90.  
  91.  
  92. WRITE_HANDLER( mario_gfxbank_w )
  93. {
  94.     if (gfx_bank != (data & 1))
  95.     {
  96.         memset(dirtybuffer,1,videoram_size);
  97.         gfx_bank = data & 1;
  98.     }
  99. }
  100.  
  101.  
  102.  
  103. WRITE_HANDLER( mario_palettebank_w )
  104. {
  105.     if (palette_bank != (data & 1))
  106.     {
  107.         memset(dirtybuffer,1,videoram_size);
  108.         palette_bank = data & 1;
  109.     }
  110. }
  111.  
  112.  
  113.  
  114. /***************************************************************************
  115.  
  116.   Draw the game screen in the given osd_bitmap.
  117.   Do NOT call osd_update_display() from this function, it will be called by
  118.   the main emulation engine.
  119.  
  120. ***************************************************************************/
  121. void mario_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  122. {
  123.     int offs;
  124.  
  125.  
  126.     /* for every character in the Video RAM, check if it has been modified */
  127.     /* since last time and update it accordingly. */
  128.     for (offs = videoram_size - 1;offs >= 0;offs--)
  129.     {
  130.         if (dirtybuffer[offs])
  131.         {
  132.             int sx,sy;
  133.  
  134.  
  135.             dirtybuffer[offs] = 0;
  136.  
  137.             sx = offs % 32;
  138.             sy = offs / 32;
  139.  
  140.             drawgfx(tmpbitmap,Machine->gfx[0],
  141.                     videoram[offs] + 256 * gfx_bank,
  142.                     (videoram[offs] >> 5) + 8 * palette_bank,
  143.                     0,0,
  144.                     8*sx,8*sy,
  145.                     0,TRANSPARENCY_NONE,0);
  146.         }
  147.     }
  148.  
  149.  
  150.     /* copy the temporary bitmap to the screen */
  151.     {
  152.         int scrolly;
  153.  
  154.         /* I'm not positive the scroll direction is right */
  155.         scrolly = -*mario_scrolly - 17;
  156.         copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  157.     }
  158.  
  159.     /* Draw the sprites. */
  160.     for (offs = 0;offs < spriteram_size;offs += 4)
  161.     {
  162.         if (spriteram[offs])
  163.         {
  164.             drawgfx(bitmap,Machine->gfx[1],
  165.                     spriteram[offs + 2],
  166.                     (spriteram[offs + 1] & 0x0f) + 16 * palette_bank,
  167.                     spriteram[offs + 1] & 0x80,spriteram[offs + 1] & 0x40,
  168.                     spriteram[offs + 3] - 8,240 - spriteram[offs] + 8,
  169.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  170.         }
  171.     }
  172. }
  173.